package com.ss.android.account.b.a;

import android.content.Context;
import android.os.Message;
import android.text.TextUtils;
import com.ss.android.account.bb;
import com.ss.android.account.Spipe;
import com.ss.android.account.model.BaseUser;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.http.legacy.a.NameValueImpl;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;

public final class a extends AbsApiThread {
    private int a;
    private BaseUser b;
    private String c;
    private Message d;

    public a(int arg2, Message arg3, BaseUser arg4, String arg5) {

        this.a = arg2;
        this.d = arg3;
        if(this.d != null) {
            this.d.obj = arg4;
        }

        this.b = arg4;
        this.c = arg5;
    }

    private int a(int arg11) {
        int v1_3;
        JSONObject v2_1;
        JSONObject v3 = null;
        int v0 = 18;
        String v1_1;
        switch(arg11) {
            case 1: {
                v1_1 = Spipe.relationFollowV2Url;
                break;

            }
            case 2: {
                v1_1 = Spipe.relationUnfollowUrl;
                break;
            }
            default:
                return v0;


        }
        try {
            ArrayList v2 = new ArrayList();
            v2.add(new NameValueImpl("user_id", this.b.mUserId+""));
            if(!android.support.design.a.isTextEmpty(this.c)) {
                v2.add(new NameValueImpl("source", this.c));
            }

            v2.add(new NameValueImpl("reason", this.b.mReasonType+""));
            if(!android.support.design.a.isTextEmpty(this.b.mNewReason)) {
                v2.add(new NameValueImpl("new_reason", this.b.mNewReason));
            }

            v2.add(new NameValueImpl("new_source", this.b.mNewSource));
            v1_1 = NetworkUtils.executePost(4096, v1_1, ((List)v2));
            if(android.support.design.a.isTextEmpty(v1_1)) {
                return v0;
            }

            v2_1 = new JSONObject(v1_1);
            if(!AbsApiThread.isApiSuccess(v2_1)) {
                JSONObject v1_2 = v2_1.getJSONObject("data");
                if(v1_2 != null && v1_2.optInt("error_code") == 1408) {
                    this.b.setIsBlocked(true);
                }

                if(v1_2 != null && !TextUtils.isEmpty(v1_2.optString("description"))) {
                    this.b.mFailReason = v1_2.optString("description");
                }

                if(!"session_expired".equals(v1_2.optString("name"))) {
                    return v0;
                }

                return 105;
            }

            v1_3 = 1009;
            v2_1 = v2_1.optJSONObject("data");
            if(v2_1 != null) {
                v2_1 = v2_1.optJSONObject("user");
            } else {
                v2_1 = v3;
            }
            this.b.extractIsFollowed(v2_1);
            this.b.extractIsFollowing(v2_1);
            this.b.extractMediaId(v2_1);
            v0 = v1_3;
        }
        catch(Throwable v1) {
            v1_3 = bb.a().a(((Context)null), v1);
            if(v1_3 == 0) {
                return v0;
            }

            v0 = v1_3;
        }

        return v0;



    }

    private int b(int arg10) {
        int v1_2;
        int v0 = 18;
        String v1_1;
        boolean v2;
        switch(arg10) {
            case 3: {
                v1_1 = Spipe.userBlockCreateUrl;
                v2 = true;
                break;
            }
            case 4: {
                v1_1 = Spipe.userBlockCancelUrl;
                v2 = false;
              break;
            }
            default:return v0;
        }

        try {
            UrlBuilder v3 = new UrlBuilder();
            v3.mUrl = v1_1;
            v3.addParam("block_user_id", this.b.mUserId);
            v1_1 = NetworkUtils.doGet(-1, v3.build());
            if(android.support.design.a.isTextEmpty(v1_1)) {
                return v0;
            }

            JSONObject v3_1 = new JSONObject(v1_1);
            if(!AbsApiThread.isApiSuccess(v3_1)) {
                if(!"session_expired".equals(v3_1.getJSONObject("data").optString("name"))) {
                    return v0;
                }

                return 105;
            }

            v1_2 = 1009;
            if(this.b.mUserId == v3_1.optJSONObject("data").optLong("block_user_id")) {
                this.b.setIsBlocking(v2);
            }
        } catch(Throwable v1) {
            v1_2 = bb.a().a(null, v1);
            if(v1_2 != 0) {
                v0 = v1_2;
            }
            else {
            }

            return v0;
        }
        return v1_2;

    }

    public final void run() {
        int v0 = 18;
        switch(this.a) {
            case 1: 
            case 2: {
                v0 = this.a(this.a);
                break;
            }
            case 3: 
            case 4: {
                v0 = this.b(this.a);
                break;
            }
        }

        if(this.d != null && this.d.getTarget() != null) {
            this.d.arg1 = v0;
            this.d.sendToTarget();
        }
    }
}

